﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;
using HRM.DAL.Report;

namespace HRM.UI.HRManagerUI.PunishmentUI
{
    public partial class ReleaseFormPunishment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                container.Visible = false;
            }
        }
        protected void FindPunishedEmployee(object o, EventArgs e)
        {
            try
            {
                List<ViewAllPunisedmentEmployee> viewAllPunisedmentEmployees = new List<ViewAllPunisedmentEmployee>();
                PunishmentManager manager = new PunishmentManager();
                Code code = new Code();
                PunishmentType type = new PunishmentType();
                code.CodeName = txtSearchByCode.Value;
                if (code.CodeName != "")
                {
                    viewAllPunisedmentEmployees = manager.GetAllPunishedEmployee(code);
                    if (viewAllPunisedmentEmployees.Count > 0)
                    {
                        container.Visible = true;
                        msgLbl.Text = "";
                    }
                    else
                    {
                        container.Visible = false;
                        msgLbl.Text = "Employee Not Found, Check Employee Code !";
                        msgLbl.ForeColor = Color.Red;
                    }
                    foreach (ViewAllPunisedmentEmployee viewEmployee in viewAllPunisedmentEmployees)
                    {
                        lblEmployeeCode.Text = viewEmployee.EmpCode;
                        lblEmloyeeName.Text = viewEmployee.Name;
                        lblDesignation.Text = viewEmployee.Designation;
                        lblProjectName.Text = viewEmployee.Project;
                        selectPunishmentType.Text = viewEmployee.Punishment;
                        lblPunishedProcedure.Text = viewEmployee.PunishedProcedure;
                        lblPunishedmentApplyDate.Text = viewEmployee.Date.ToShortDateString();
                        lblRemarks.Text = viewEmployee.Remarks;
                        lblPunishedBy.Text = viewEmployee.PunishedBy;
                        lblPunishmentStatus.Text = viewEmployee.Status;
                        ViewState["punishedId"] = viewEmployee.Id;
                    }
                }

            }
            catch (Exception ex)
            {
                msgLbl.Text = ex.Message;
                msgLbl.ForeColor = Color.Red;
            }
        }

        protected void ReleasePunishment(object o,EventArgs e)
        {
            Punishment punishment=new Punishment();
            punishment.Id = (int)ViewState["punishedId"];
            punishment.Remarks = lblRemarks.Text;
            punishment.Status = ddlStatus.Value;
            punishment.ReleaseDate =Convert.ToDateTime(txtDate.Value);
            punishment.ReleaseBy = txtReleaseBy.Value;

            PunishmentManager manager=new PunishmentManager();
            if(manager.ReleaseFromPunishment(punishment))
            {
                msgLbl.Text = "Successfully Changed Employee's Punishment Status";
                msgLbl.ForeColor = Color.Green; 
            }
            else
            {
                msgLbl.Text = "Punishment Status not Changed";
                msgLbl.ForeColor = Color.Green; 
            }
        }
    }
}